package com.wp.common;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;

/*
 * 查询的工具类
 */
public class CURDUtil {
	
	private static SqlSessionTemplate sqlDao;
	public static void setSqlDao(SqlSessionTemplate sqlDao) {
		CURDUtil.sqlDao = sqlDao;
	}
	
	//查询一条结果方法
	@SuppressWarnings({ "rawtypes" })
	public static Object queryObject(String sql,Map params){
		Object obj1 = sqlDao.selectOne(sql, params);
		return obj1;
	}
	
	//查询一条结果方法2
	public static Object queryObject(String sql,Object obj){
		Object obj1 = sqlDao.selectOne(sql, obj);
		return obj1;
	}
	
	//查询结果为集合的返回
	@SuppressWarnings("rawtypes")
	public static List queryList(String sql,Map params){
		Object obj1 = sqlDao.selectList(sql, params);
		return (List)obj1;
	}
	
	//查询结果为集合的返回2
	public static List<?> queryList(String sql,Object obj){
		Object obj1 = sqlDao.selectList(sql, obj);
		return (List)obj1;
	}
		
	//更新数据
	@SuppressWarnings({ "rawtypes" })
	public static Integer update(String sql,Map params){
		Object obj1 = sqlDao.update(sql, params);
		return (Integer)obj1;
	}
	
	//更新数据2
	public static Integer update(String sql,Object obj){
		Object obj1 = sqlDao.update(sql, obj);
		return (Integer)obj1;
	}
		
	//新增数据
	@SuppressWarnings({ "rawtypes" })
	public static Integer insert(String sql,Map params){
		Object obj1 = sqlDao.insert(sql, params);
		return (Integer)obj1;
	}
	
	//新增数据2
	public static Integer insert(String sql,Object obj){
		Object obj1 = sqlDao.insert(sql, obj);
		return (Integer)obj1;
	}
		
	//删除数据
	@SuppressWarnings({ "rawtypes" })
	public static Integer delete(String sql,Map params){
		Object obj1 = sqlDao.delete(sql, params);
		return (Integer)obj1;
	}
	
	//删除数据2
	public static Integer delete(String sql,Object obj){
		Object obj1 = sqlDao.delete(sql, obj);
		return (Integer)obj1;
	}
}
